home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 209 < prev    next >
Text File  |  1996-08-06  |  3KB  |  108 lines

  1. Path: news.compuserve.com!newsmaster
  2. From: Piet Starreveld <101476.1040@compuserve.com>
  3. Newsgroups: comp.std.c
  4. Subject: Re: How to calculate the Holy Easter.
  5. Date: 28 Jan 1996 18:34:48 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4egfk8$clg@dub-news-svc-4.compuserve.com>
  8. References: <4e5kmh$2g9@leporello.cs.unibo.it>
  9. NNTP-Posting-Host: hd19-014.compuserve.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; I; 16bit)
  14. To: chierici@cs.unibo.it
  15.  
  16. Hi,
  17.  
  18. on January 24, 1996 you wrote:
  19.  
  20. > Hi, can anybody send me a C function to calculate the Easter of every 
  21. > year? Thanks in advance,
  22. >                         Andrea.
  23.  
  24. Then this guy came up with a Gauss algorithm put into a Pascal (yagh!) 
  25. procedure:
  26.  
  27. Abe Timmerman
  28. Hogeschool Holland
  29. (HHIT: Center for education and Information Technology)
  30. The Netherlands
  31. Email:A.Timmerman@Beta.hsholland.nl
  32.  
  33. Next ofcourse somebody asked for the C version, which you did in the 
  34. first place. 
  35.  
  36. Below you will find the Pascal procedure converted to a C function
  37. and a (tested) sample program that calls the function. This is by far
  38. not the most elegant C function I have ever seen, but it is meant 
  39. to follow the Pascal procedure step by step. I do not know if limits
  40. for the year exist and if so what they are (besides ofcourse the obvious
  41. ones), I did not test for any:
  42.  
  43. =========================================================================
  44. #include    <stdio.h>
  45.  
  46. void    Easter(int * Month, int * Day, int Year);
  47.  
  48. void    main()
  49. {
  50.     int y, m, d;
  51.  
  52.     for (y = 1800; y <= 2000; y++) {
  53.         Easter(&m, &d, y);             
  54.         printf("Year: %4d, Month: %2d, Day: %2d\n", y, m, d);
  55.     }
  56.  
  57. }
  58.  
  59.  
  60. /*
  61.     C version for the Gauss-Easter algorithm
  62.  
  63.     Based on the formulas/algorithm published bij Gauss in 1800
  64.  
  65.     Input:            - pointers to ints Month and Day
  66.                       - int Year where 1800 <= Year <= 2000 (?)
  67.  
  68.     Input-validation: none (sensible input assumed for Year)
  69.  
  70. */
  71. void    Easter(int * Month, int * Day, int Year)
  72. {
  73.     int a, b, c, d, e, f, k, m, n, p, q;
  74.  
  75.     a = Year % 19;
  76.     b = Year % 4;
  77.     c = Year % 7;
  78.     k = Year / 100;
  79.     p = k / 3;
  80.     q = k - k / 4;
  81.     m = (q - p + 15) % 30;
  82.     n = (q + 4) % 7;
  83.     d = (19 * a + m) % 30;
  84.     e = (2 * b + 4 * c + 6 * d + n) % 7;
  85.     f = d + e - 9;
  86.     if  (f <= 0) {
  87.         *Month = 3;
  88.         *Day = 31 + f;
  89.     }
  90.     else {
  91.         *Month = 4;
  92.         if   (f == 26)
  93.             *Day = 19;
  94.         else if (f == 25 && d == 28)
  95.             *Day = 18;
  96.         else
  97.             *Day = f;
  98.     }
  99. }
  100. =========================================================================
  101.  
  102. Hope this helps,
  103.  
  104. Piet Starreveld
  105. e-mail:101476.1040@compuserve.com
  106.  
  107.  
  108.